export default{
    install:function (Vue) {
        //日期加减
        //<param name="datepart" type="string">
        //日期加减的部分:
        //Year, yy, yyyy--年
        //quarter, qq, q --季
        //Month, mm, m --    月
        //dayofyear, dy, y--    日
        //Day, dd, d --    日
        //Week, wk, ww --    周
        //Hour, hh --    小时
        //minute, mi, n --    分钟
        //second, ss, s --    秒
        //millisecond, ms --    毫秒
        //</param>
        //<param name="number" type="int">
        //要加减的数量
        //</param>
        //<param name="returnNewObjec" type="bool">
        //若参数为true值，则操作结果由一个新的日期对象返回，原日期对象不变；
        //否则返回的是原日期对象,此时原日期对象的值是操作结果.
        //</param>
        //<returns type="Date">返回一个日期对象
        //调用例子：new Date().add('dayofyear',1,true)
        Date.prototype.add= function(datepart, number, returnNewObjec=true) {

                datepart = datepart.toLowerCase();
                var tDate;
                if (typeof (returnNewObjec) == "boolean") {
                    if (returnNewObjec == true) {
                        tDate = new Date(this);
                    }
                    else { tDate = this; }
                }
                else { tDate = this; }

                switch (datepart) {
                    case "year":
                    case "yy":
                    case "yyyy":
                        tDate.setFullYear(this.getFullYear() + number);
                        break;
                    case "quarter":
                    case "qq":
                    case "q":
                        tDate.setMonth(this.getMonth() + (number * 3));
                        break;
                    case "month":
                    case "mm":
                    case "m":
                        tDate.setMonth(this.getMonth() + number);
                        break;
                    case "dayofyear":
                    case "dy":
                    case "y":
                    case "day":
                    case "dd":
                    case "d":
                        tDate.setDate(this.getDate() + number);
                        break;
                    case "week":
                    case "wk":
                    case "ww":
                        tDate.setDate(this.getDate() + (number * 7));
                        break;
                    case "hour":
                    case "hh":
                        tDate.setHours(this.getHours() + number);
                        break
                    case "minute":
                    case "mi":
                    case "n":
                        tDate.setMinutes(this.getMinutes() + number);
                        break
                    case "second":
                    case "ss":
                    case "s":
                        tDate.setSeconds(this.getSeconds() + number);
                        break;
                    case "millisecond":
                    case "ms":
                        tDate.setMilliseconds(this.getMilliseconds() + number);
                        break;
                }
                return tDate;
            }
        Date.prototype.format = function(fmt) {
            var o = {
                "M+" : this.getMonth()+1,                 //月份
                "d+" : this.getDate(),                    //日
                "h+" : this.getHours(),                   //小时
                "m+" : this.getMinutes(),                 //分
                "s+" : this.getSeconds(),                 //秒
                "q+" : Math.floor((this.getMonth()+3)/3), //季度
                "S"  : this.getMilliseconds()             //毫秒
            };
            if(/(y+)/.test(fmt)) {
                fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
            }
            for(var k in o) {
                if(new RegExp("("+ k +")").test(fmt)){
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
                }
            }
            return fmt;
        }

    }


}